<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
<script src="../res/layui/layui.js"></script>
</head>

<body>
	<form id='form_add' class="layui-form" action=""
		style="width: 60%; margin-top: 10px;" lay-filter="form_add">
		<div class="layui-form-item">
			<label class="layui-form-label">登录名</label>
			<div class="layui-input-block">
				<input type="text" name="loginnam" placeholder="" autocomplete="off"
					class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">登录密码</label>
			<div class="layui-input-block">
				<input type="text" name="password" placeholder=""
					autocomplete="off" class="layui-input">
			</div>
		</div>
         <div class="layui-form-item">
			<label class="layui-form-label">角色Id</label>
			<div class="layui-input-block">
				<input type="text" name="rid" placeholder=""
					autocomplete="off" class="layui-input">
			</div>
		</div>

		

		
	
	

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="add_submit">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</body>

<script>
	layui.use([ 'layer', 'form' ], function() {
		var $ = layui.$ //jquery
		, layer = layui.layer //弹层
		, form = layui.form //表单	

		//加载班级下拉框
		$.post("http://localhost:8080/g4/admin/selsctOpResults", {},
				function(result) {
					if (result.code === '0') {
						$.each(result.data, function(index, item) {
							$('#categoryid').append(
									new Option(item.value, item.view));// 下拉菜单里添加元素
						});
						form.render('select');

					} else {
						layer.alert(result.msg);
					}
				}, "json");

		//点击添加按钮
		form.on('submit(add_submit)', function(data) {
			var str = $("#form_add").serialize();
			$
					.post("http://localhost:8080/g4/admin/addOne",
							str, function(result) {
								if (result.code === '0') {
									parent.layer.alert(result.msg);

									//当你在iframe页面关闭自身时
									var index = parent.layer
											.getFrameIndex(window.name); //先得到当前iframe层的索引
									parent.layer.close(index); //再执行关闭   
									parent.layui.$("#shousuo").click();

								} else {
									layer.alert(result.msg);
								}
							}, "json");
			return false;
		});
	});
</script>

</html>